home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-portable.exe / quodlibet-3.3.0-portable / data / bin / functools.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  6KB  |  124 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''functools.py - Tools for working with functions and callable objects
  5. '''
  6. from _functools import partial, reduce
  7. WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
  8. WRAPPER_UPDATES = ('__dict__',)
  9.  
  10. def update_wrapper(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES):
  11.     '''Update a wrapper function to look like the wrapped function
  12.  
  13.        wrapper is the function to be updated
  14.        wrapped is the original function
  15.        assigned is a tuple naming the attributes assigned directly
  16.        from the wrapped function to the wrapper function (defaults to
  17.        functools.WRAPPER_ASSIGNMENTS)
  18.        updated is a tuple naming the attributes of the wrapper that
  19.        are updated with the corresponding attribute from the wrapped
  20.        function (defaults to functools.WRAPPER_UPDATES)
  21.     '''
  22.     for attr in assigned:
  23.         setattr(wrapper, attr, getattr(wrapped, attr))
  24.     
  25.     for attr in updated:
  26.         getattr(wrapper, attr).update(getattr(wrapped, attr, { }))
  27.     
  28.     return wrapper
  29.  
  30.  
  31. def wraps(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES):
  32.     '''Decorator factory to apply update_wrapper() to a wrapper function
  33.  
  34.        Returns a decorator that invokes update_wrapper() with the decorated
  35.        function as the wrapper argument and the arguments to wraps() as the
  36.        remaining arguments. Default arguments are as for update_wrapper().
  37.        This is a convenience function to simplify applying partial() to
  38.        update_wrapper().
  39.     '''
  40.     return partial(update_wrapper, wrapped = wrapped, assigned = assigned, updated = updated)
  41.  
  42.  
  43. def total_ordering(cls):
  44.     '''Class decorator that fills in missing ordering methods'''
  45.     convert = {
  46.         '__lt__': [
  47.             ('__gt__', (lambda self, other: if not self < other:
  48. passnot (self == other))),
  49.             ('__le__', (lambda self, other: if not self < other:
  50. passself == other)),
  51.             ('__ge__', (lambda self, other: not (self < other)))],
  52.         '__le__': [
  53.             ('__ge__', (lambda self, other: if not not (self <= other):
  54. passself == other)),
  55.             ('__lt__', (lambda self, other: if self <= other:
  56. passnot (self == other))),
  57.             ('__gt__', (lambda self, other: not (self <= other)))],
  58.         '__gt__': [
  59.             ('__lt__', (lambda self, other: if not self > other:
  60. passnot (self == other))),
  61.             ('__ge__', (lambda self, other: if not self > other:
  62. passself == other)),
  63.             ('__le__', (lambda self, other: not (self > other)))],
  64.         '__ge__': [
  65.             ('__le__', (lambda self, other: if not not (self >= other):
  66. passself == other)),
  67.             ('__gt__', (lambda self, other: if self >= other:
  68. passnot (self == other))),
  69.             ('__lt__', (lambda self, other: not (self >= other)))] }
  70.     roots = set(dir(cls)) & set(convert)
  71.     if not roots:
  72.         raise ValueError('must define at least one ordering operation: < > <= >=')
  73.     root = max(roots)
  74.     for opname, opfunc in convert[root]:
  75.         if opname not in roots:
  76.             opfunc.__name__ = opname
  77.             opfunc.__doc__ = getattr(int, opname).__doc__
  78.             setattr(cls, opname, opfunc)
  79.             continue
  80.     return cls
  81.  
  82.  
  83. def cmp_to_key(mycmp):
  84.     '''Convert a cmp= function into a key= function'''
  85.     
  86.     class K((object,)):
  87.         __slots__ = [
  88.             'obj']
  89.         
  90.         def __init__(self, obj, *args):
  91.             self.obj = obj
  92.  
  93.         
  94.         def __lt__(self, other):
  95.             return mycmp(self.obj, other.obj) < 0
  96.  
  97.         
  98.         def __gt__(self, other):
  99.             return mycmp(self.obj, other.obj) > 0
  100.  
  101.         
  102.         def __eq__(self, other):
  103.             return mycmp(self.obj, other.obj) == 0
  104.  
  105.         
  106.         def __le__(self, other):
  107.             return mycmp(self.obj, other.obj) <= 0
  108.  
  109.         
  110.         def __ge__(self, other):
  111.             return mycmp(self.obj, other.obj) >= 0
  112.  
  113.         
  114.         def __ne__(self, other):
  115.             return mycmp(self.obj, other.obj) != 0
  116.  
  117.         
  118.         def __hash__(self):
  119.             raise TypeError('hash not implemented')
  120.  
  121.  
  122.     return K
  123.  
  124.